package com.aaa.day1104.demo2;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年11月04日10:33
 */
public class Test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"张三","张十三","李四");

        list.stream().filter(item->item.startsWith("张"))
                .filter(item->item.length()==2)
                .forEach(item-> System.out.println("item = " + item));
    }
    public static void fun(){
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三","张十三","李四");

        //所有姓张的
        ArrayList<String> newList = new ArrayList<>();
        for(String n:list){
            if(n.startsWith("张")){
                newList.add(n);
            }
        }

        //名字中含有几个的字
        ArrayList<String> newList2 = new ArrayList<>();
        for(String n:newList){
            if(n.length()==2){
                newList2.add(n);
            }
        }

        for (String s:newList2){
            System.out.println(s);
        }

    }
}















